import { useQuery } from '@apollo/client';
import { propEq } from 'ramda';

import { useMappedConnection } from '../../../shared/hooks';
import { {{ camelCase name }}ListQuery } from '../{{ camelCase name }}List/{{ camelCase name }}List.graphql';

export const use{{ pascalCase name }} = (id: string) => {
  const { data, loading } = useQuery({{ camelCase name }}ListQuery);
  const allItems = useMappedConnection(data?.{{ camelCase name }}List);

  const itemData = allItems.find(propEq('id', id));

  return { itemData, loading };
};
